package com.pa165.languageschoolpersistence.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

/**
 *
 * @author Tomas Hruby
 *
 * Class representing entity Student. Student is an entity in language school,
 * that enrolls for courses.
 * @attribute ID students id, generated automatically, cannot be 0.
 * @attribute name name of student. Must contain only small or large letters,
 * without punctation or special characters.
 * @attribute surname surname of student. Must contain only small or large
 * letters, without punctation or special characters.
 * @attribute lectures list of lectures that student enrolls. If student enrolls
 * a lecture, he automatically enrolls a course. Student can enroll 0..*
 * lectures.
 * @attribute courses list of courses Student enrolls. Courses are calculated
 * from enrolled lectures. Student can enroll 0..* lectures.
 */
@Entity
public class Student implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    private String surname;
    private String userName;
    private String pwd;
    private String userRole;
    
    @ManyToMany
    @JoinTable(
            name = "student_lecture",
    joinColumns = {
        @JoinColumn(name = "students_id", referencedColumnName = "id")},
    inverseJoinColumns = {
        @JoinColumn(name = "lectures_id", referencedColumnName = "id")})
    private List<Lecture> lectures = new ArrayList<Lecture>();

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }
    
    

    public void addLecture(Lecture lecture) {
        if (lectures != null) {
            lectures.add(lecture);
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Lecture> getLectures() {
        return lectures;
    }

    public void setLectures(List<Lecture> lectures) {
        this.lectures = lectures;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUserRole() {
        return userRole;
    }

    public void setUserRole(String userRole) {
        this.userRole = userRole;
    }

    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {

        if (!(object instanceof Student)) {
            return false;
        }
        Student other = (Student) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }

        return true;
    }

    @Override
    public String toString() {
        return "Student[ id=" + id + ", name=" + name + "]";
    }
}
